package org.jeecg.modules.weixin;

import com.alibaba.fastjson.JSON;
import org.jeecg.modules.demo.msgtemplatelist.service.IMsgTemplateService;
import org.jeecg.modules.demo.reserverecord.entity.ReserveRecord;
import org.jeecg.modules.util.WxUtils;
import org.jeecg.modules.weixin.entity.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public class util {
    /**
     * 会员等级变更通知
     * @param userOpenId
     * @param originalLevel
     * @param nowLevel
     * @param discount
     */
    public  static void levelChangeNotice(String templateId,String userOpenId, String originalLevel, String nowLevel, String discount, String xcxAppId, String pagepath, String accessToken)// "/pages/index/index"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("会员等级变更通知", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(originalLevel, "#173177");
        Keyword keyword2 = new Keyword(nowLevel, "#173177");
        Keyword keyword3 = new Keyword(discount, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("您将享受新的会员等级折扣政策", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 消费提醒
     * @param userOpenId
     * @param consumeDate
     * @param consumeAmount
     * @param consumeStore
     */
    public  static void consumeNotice(String templateId,String userOpenId, String consumeDate, String consumeAmount, String consumeStore, String xcxAppId, String pagepath, String accessToken)// "user/order/index?type=0"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您已消费成功！", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(consumeDate, "#173177");
        Keyword keyword2 = new Keyword(consumeAmount, "#173177");
        Keyword keyword3 = new Keyword(consumeStore, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("祝您生活愉快！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 退款通知
     * @param userOpenId
     * @param merchantName
     * @param refundAmount
     * @param orderCode
     * @param refundTime
     */
    public  static void refundNotice(String templateId,String userOpenId, String merchantName, String refundAmount, String orderCode, String refundTime, String xcxAppId, String pagepath, String accessToken)// "user/order/index?type=0"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您有一笔订单退款成功！", "");
        Keyword[] keywords = new Keyword[4];
        Keyword keyword1 = new Keyword(merchantName, "#173177");
        Keyword keyword2 = new Keyword(refundAmount, "#173177");
        Keyword keyword3 = new Keyword(orderCode, "#173177");
        Keyword keyword4 = new Keyword(refundTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;
        keywords[3] = keyword4;

        Remark remark = new Remark("如有疑问，请联系商家了解详情", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 成为会员通知
     * @param userOpenId
     * @param nickName
     * @param memberPhone
     */
    public  static void becomeMemberNotice(String userOpenId,String nickName,String memberPhone)
    {
        Miniprogram miniprogram = new Miniprogram("wxf9e3094d80bfe883", "/pages/index/index");
        First first = new First("尊敬的用户您好！", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(nickName, "#173177");
        Keyword keyword2 = new Keyword(memberPhone, "#173177");
        Keyword keyword3 = new Keyword(memberPhone, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("恭喜您成为本店会员，感谢您的使用！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, "cctIRpfGprwvfWiTb5cDTTMIm6h4m1yokc3mmmsAwBo", "https://#", miniprogram, data);
        WxUtils.sendMessage2(WxUtils.getAccessToken().get("access_token"), jsonRootBean);
    }

    /**
     * 订单核销成功提醒
     * @param userOpenId
     * @param orderCode
     * @param storeName
     * @param storeName
     * @param writeoffTime
     */
    public  static void orderWriteoffNotice(String templateId,String userOpenId, String orderCode, String commodityName,String storeName, String writeoffTime, String xcxAppId, String pagepath, String accessToken)// "shop/goods/pay?active=1"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("尊敬的会员，您已成功自提商品", "");
        Keyword[] keywords = new Keyword[4];
        Keyword keyword1 = new Keyword(orderCode, "#173177");
        Keyword keyword2 = new Keyword(commodityName, "#173177");
        Keyword keyword3 = new Keyword(storeName, "#173177");
        Keyword keyword4 = new Keyword(writeoffTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;
        keywords[3] = keyword4;

        Remark remark = new Remark("感谢您的使用！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * PC下发新人卡、通用卡给用户发的通知
     * @param userOpenId
     * @param noticeContent
     * @param noticeTime
     */
    public  static void unclaimedCardNotice2(String templateId,String userOpenId, String noticeContent, String noticeTime, String xcxAppId, String pagepath, String accessToken)// "shop/guest/info"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您有一份待领取的贵宾卡！", "");
        Keyword[] keywords = new Keyword[2];
        Keyword keyword1 = new Keyword(noticeContent, "#173177");
        Keyword keyword2 = new Keyword(noticeTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;

        Remark remark = new Remark("点击此消息立即领取！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * PC下发新人卡、通用卡给用户发的通知
     * @param userOpenId
     * @param noticeContent
     * @param noticeTime
     */
    public  static void unclaimedCardNotice(String templateId,String userOpenId, String noticeContent, String noticeTime, String xcxAppId, String pagepath, String accessToken)// "shop/guest/info"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您有一份待领取的贵宾卡！", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword("尊敬的客户", "#173177");
        Keyword keyword2 = new Keyword(noticeContent, "#173177");
        Keyword keyword3 = new Keyword(noticeTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("点击此消息立即领取！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 提现成功提醒
     * @param userOpenId
     * @param withdrawalAmount
     * @param withdrawalTime
     */
    public  static void withdrawalSuccessNotice(String templateId,String userOpenId, String withdrawalAmount, String withdrawalTime, String xcxAppId, String pagepath, String accessToken)// "usr/share/drawal"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("尊敬的股东，您的提现申请已通过，请注意查收！", "");
        Keyword[] keywords = new Keyword[2];
        Keyword keyword1 = new Keyword(withdrawalAmount, "#173177");
        Keyword keyword2 = new Keyword(withdrawalTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;

        Remark remark = new Remark("祝您生活愉快！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 提现驳回通知
     * @param userOpenId
     * @param userName
     * @param withdrawalAmount
     * @param rejectTime
     */
    public  static void withdrawalRjectNotice(String templateId,String userOpenId, String userName, String withdrawalAmount, String rejectTime, String xcxAppId, String pagepath, String accessToken)// "user/share/drawal"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您的提现申请已被驳回", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(userName, "#173177");
        Keyword keyword2 = new Keyword(withdrawalAmount, "#173177");
        Keyword keyword3 = new Keyword(rejectTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("商家已驳回您提现申请，请与商家联系！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 成为合伙人提醒
     * @param userOpenId
     * @param userName
     * @param becomeTime
     */
    public  static void becomeStockNotice(String templateId,String userOpenId,String userName,String becomeTime, String xcxAppId, String pagepath, String accessToken)// "pages/user/index"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("恭喜您成为我们的合伙人！", "");
        Keyword[] keywords = new Keyword[2];
        Keyword keyword1 = new Keyword(userName, "#173177");
        Keyword keyword2 = new Keyword(becomeTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;

        Remark remark = new Remark("感谢您的支持！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 推荐会员成功通知
     * @param userOpenId
     * @param userCode
     * @param successTime
     */
    public  static void recommendMemberSuccessNotice(String templateId,String userOpenId, String userCode, String successTime, String xcxAppId, String pagepath, String accessToken)// "/user/share/tourist"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("尊敬的股东，恭喜您成功拓展一位会员！", "");
        Keyword[] keywords = new Keyword[2];
        Keyword keyword1 = new Keyword(userCode, "#173177");
        Keyword keyword2 = new Keyword(successTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;

        Remark remark = new Remark("", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 用户退款通知
     * @param userOpenId
     * @param memberName
     * @param refundReason
     * @param refundAmount
     * @param refundTime
     */
    public  static void memberRefundNotice(String templateId,String userOpenId, String memberName, String refundReason, String refundAmount, String refundTime, String xcxAppId, String pagepath, String accessToken)// "user/share/bonus"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您推荐的会员有一笔新的退款", "");
        Keyword[] keywords = new Keyword[4];
        Keyword keyword1 = new Keyword(memberName, "#173177");
        Keyword keyword2 = new Keyword(refundReason, "#173177");
        Keyword keyword3 = new Keyword(refundAmount, "#173177");
        Keyword keyword4 = new Keyword(refundTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;
        keywords[3] = keyword4;

        Remark remark = new Remark("该笔订单产生的分红将会扣除！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 订单分红提醒
     * @param userOpenId
     * @param thisAmount
     * @param totalAmount
     * @param orderTime
     */
    public  static void orderDividendNotice(String templateId,String userOpenId,String thisAmount,String totalAmount,String orderTime, String xcxAppId, String pagepath, String accessToken)// "user/share/bonus"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("恭喜您，您有新的分红收益！", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(thisAmount, "#173177");
        Keyword keyword2 = new Keyword(totalAmount, "#173177");
        Keyword keyword3 = new Keyword(orderTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 通过PC给股东下发拓客卡给股东的消息通知
     * @param userOpenId
     * @param cardName
     * @param noticeTime
     */
    public  static void sendTokerCardNotice(String templateId,String stockName,String userOpenId, String cardName, String noticeTime, String xcxAppId, String pagepath, String accessToken)// "user/toker/index"
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您有新的拓客卡已发送至您的账户中请查收！", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(stockName, "#173177");
        Keyword keyword2 = new Keyword(cardName, "#173177");
        Keyword keyword3 = new Keyword(noticeTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 提现申请审批通知
     * @param userOpenId
     * @param applyPerson
     * @param withdrawalAmount
     * @param applyTime
     */
    public  static void withdrawalApplyApproveNotice(String templateId,String userOpenId,String applyPerson,String withdrawalAmount,String applyTime, String xcxAppId, String pagepath, String accessToken)
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您有一笔提现申请待处理", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(applyPerson, "#173177");
        Keyword keyword2 = new Keyword(withdrawalAmount, "#173177");
        Keyword keyword3 = new Keyword(applyTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("请尽快处理！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 新增成员提醒
     * @param userOpenId
     * @param memberName
     * @param addTime
     * @param invitePerson
     */
    public  static void addMemberNotice(String templateId,String userOpenId,String memberName,String addTime,String invitePerson, String xcxAppId, String pagepath, String accessToken)
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("恭喜您！又新增了一位新会员！", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(memberName, "#173177");
        Keyword keyword2 = new Keyword(addTime, "#173177");
        Keyword keyword3 = new Keyword(invitePerson, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark("快去看看吧！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 库存不足提醒
     * @param userOpenId
     * @param commodityName
     * @param remainInventory
     * @param noticeTime
     */
    public  static void inventoryInsufficientNotice(String templateId,String userOpenId,String commodityName,String remainInventory,String noticeTime, String xcxAppId, String pagepath, String accessToken)
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("产品："+commodityName, "");
        Keyword[] keywords = new Keyword[2];
        Keyword keyword1 = new Keyword(remainInventory, "#173177");
        Keyword keyword2 = new Keyword(noticeTime, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;

        Remark remark = new Remark("请尽快补充库存。", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    /**
     * 商家自提订单提醒
     * @param userOpenId
     * @param orderCode
     * @param orderTime
     * @param memberName
     * @param memberPhone
     */
    public  static void selfMentionNotice(String templateId,String userOpenId,String orderCode,String orderTime,String memberName,String memberPhone, String xcxAppId, String pagepath, String accessToken)
    {
        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("您有新的自提订单待用户提货，请及时关注商品库存情况", "");
        Keyword[] keywords = new Keyword[4];
        Keyword keyword1 = new Keyword(orderCode, "#173177");
        Keyword keyword2 = new Keyword(orderTime, "#173177");
        Keyword keyword3 = new Keyword(memberName, "#173177");
        Keyword keyword4 = new Keyword(memberPhone, "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;
        keywords[3] = keyword4;

        Remark remark = new Remark("若商品库存不足，请及时致电下单人协商，避免用户空跑，引起客诉！", "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        WxUtils.sendMessage2(accessToken, jsonRootBean);
    }

    public static void setGzhMenu(String xcxAppId, String accessToken) {

    }

    /**
     * 预约结果提醒
     * @param userOpenId
     * @param list
     * @param result
     * @param noticeTime
     */
    public  static void prebookResultNotice(String templateId, String userOpenId, List<String> list, String result, String noticeTime, String xcxAppId, String pagepath, String accessToken)
    {

        Miniprogram miniprogram = new Miniprogram(xcxAppId, pagepath);
        First first = new First("预约审核通知", "");
        Keyword[] keywords = new Keyword[3];
        Keyword keyword1 = new Keyword(list.get(0), "#173177");
        Keyword keyword2 = new Keyword(list.get(1), "#173177");
        Keyword keyword3 = new Keyword(list.get(2), "#173177");

        keywords[0] = keyword1;
        keywords[1] = keyword2;
        keywords[2] = keyword3;

        Remark remark = new Remark(result+"请根据结果安排行程。"+noticeTime, "");
        data data = new data(first, remark, keywords);
        JsonRootBean jsonRootBean = new JsonRootBean(userOpenId, templateId, "https://#", miniprogram, data);
        Map<String, String> map = WxUtils.sendMessage2(accessToken, jsonRootBean);
        System.out.println(JSON.toJSONString(map));
    }
}
